package com.zyy.study.demo;

import org.redisson.Redisson;
import org.redisson.api.*;
import org.redisson.config.Config;

public class RedissonDemo {
    public static final String KEY = "TokenBucketRateLimiter:";
    public static void main(String[] args) {
        RedissonClient redissonClient = RedissonConfig.getInstance();
        RSemaphore semaphore = redissonClient.getSemaphore(KEY);
        semaphore.trySetPermits(10);
    }
}
class RedissonConfig {

    private static final String REDIS_ADDRESS = "redis://101.133.170.33:6379";

    private static volatile  RedissonClient redissonClient;

    public static RedissonClient getInstance(){
        if (redissonClient==null){
            synchronized (RedissonConfig.class){
                if (redissonClient==null){
                    Config config = new Config();
                    config.useSingleServer().setAddress(REDIS_ADDRESS);
                    redissonClient = Redisson.create(config);
                    return redissonClient;
                }
            }
        }
        return redissonClient;
    }
}